SELECT t.id, t.table_id, u.id_sub FROM excel_templates t LEFT JOIN excel_uploads u ON u.id=t.table_id WHERE t.table_id = 3999}} AND t.def = 1 AND u.deleted=0 ----> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}} AND t.def = 1 AND u.deleted=0' at line 4